# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4

PortSystem          1.0
PortGroup           muniversal 1.0

name                OCPN_openssl
epoch               1
version             1.1.1l

# Please revbump these ports when updating OpenSSL.
#  - freeradius (#43461)
#  - openssh (#54990)

categories          devel security
platforms           darwin
license             OpenSSL SSLeay
maintainers         {larryv @larryv} {cal @neverpanic} openmaintainer

description         OpenSSL SSL/TLS cryptography library
long_description    The OpenSSL Project is a collaborative effort to \
                    develop a robust, commercial-grade, full-featured, \
                    and Open Source toolkit implementing the Secure \
                    Sockets Layer (SSL v2/v3) and Transport Layer \
                    Security (TLS v1) protocols as well as \
                    a full-strength general purpose cryptography \
                    library.
homepage            https://www.openssl.org

conflicts           libressl libressl-devel

depends_lib         port:zlib

distname            openssl-${version}

# See https://www.openssl.org/source/mirror.html
master_sites        ${homepage}/source \
                    ftp://gd.tuwien.ac.at/infosys/security/openssl/source/ \
                    http://mirror.switch.ch/ftp/mirror/openssl/source/ \
                    ftp://ftp.fi.muni.cz/pub/openssl/source/ \
                    ftp://ftp.pca.dfn.de/pub/tools/net/openssl/source/ \
                    http://artfiles.org/openssl.org/source/ \
                    ftp://ftp.linux.hr/pub/openssl/source/ \
                    ftp://guest.kuria.katowice.pl/pub/openssl/source/

checksums           rmd160  aa470eea95b127e7ea389c39610a7568579d6b86 \
                    sha256  0b7a3e5e59c34827fe0c3a74b7ec8baef302b98fa80088d7f9153aa16fa76bd1 \
                    size    9834044

if {${os.platform} eq "darwin" && ${os.major} < 11} {
    # Having the stdlib set to libc++ on 10.6 causes a dependency on a
    # macports-clang compiler to be added, which would be a dep cycle.
    configure.cxx_stdlib
}

# https://github.com/macports/macports-ports/commit/9ce0f93609adf300e84bdd599366a3d4ab05215d
# https://github.com/devnexen/openssl/commit/cef404f1e7a598166cbc2fd2e0048f7e2d752ad5
patch.pre_args      -p1
patchfiles-append   0001-Darwin-platform-allows-to-build-on-releases-before-Y.patch

configure.ccache    no
configure.perl      /usr/bin/perl
configure.cmd       ./Configure
configure.args      -L${prefix}/lib \
                    --openssldir=${prefix}/etc/openssl \
                    shared \
                    zlib
configure.cflags-append     "-mmacosx-version-min=10.9"

# Use SDK if necessary.
if {${configure.sdkroot} ne ""} {
    configure.args-append   '-isysroot ${configure.sdkroot}' \
                            -Wl,-syslibroot,${configure.sdkroot}
}

set merger_arch_compiler no
array set merger_configure_args {
    ppc     darwin-ppc-cc
    i386    darwin-i386-cc
    ppc64   darwin64-ppc-cc
    x86_64  darwin64-x86_64-cc
    arm64   darwin64-arm64-cc
}
platform darwin {
    # Don't use i386 assembly on Tiger (#38015, #43303).
    if {${os.major} <= 8} {
        append merger_configure_args(i386) { no-asm}
        # https://trac.macports.org/ticket/58992
        configure.args-append no-async
    }
    # Don't use x86-64 assembly on Tiger or Leopard.
    if {${os.major} <= 9} {
        append merger_configure_args(x86_64) { no-asm}
        # OpenSSL requires Perl 5.10.0, while Leopard ships Perl 5.8.8
        depends_build-append    port:perl5
        configure.perl          ${prefix}/bin/perl5
    }
}
# Don't pass --host to configure.
array set merger_host {ppc {} i386 {} ppc64 {} x86_64 {} arm64 {}}

if {![info exists universal_possible]} {
    set universal_possible [expr {${os.universal_supported} && [llength ${configure.universal_archs}] >= 2}]
}
if {(!${universal_possible} || ![variant_isset universal])
        && [info exists merger_configure_args(${configure.build_arch})]} {
    configure.args-append $merger_configure_args(${configure.build_arch})
}
configure.universal_args-delete --disable-dependency-tracking

# Parallel builds don't quite work (#46719).
use_parallel_build  no

test.run            yes

pre-destroot {
    if {[variant_exists universal] && [variant_isset universal]} {
        global merger_dont_diff
        if {[llength ${universal_archs_to_use}] > 2} {
            lappend merger_dont_diff ${prefix}/include/openssl/opensslconf.h
        }
    }
}

destroot.args       MANDIR=${prefix}/share/man MANSUFFIX=ssl

variant rfc3779 description {enable RFC 3779: X.509 Extensions for IP Addresses and AS Identifiers} {
    configure.args-append   enable-rfc3779
}

livecheck.type      regex
livecheck.url       [lindex ${master_sites} 0]
livecheck.regex     ${name}-(\[0-9.\]+\[a-z\]?)\\.tar\\.gz
